home *** CD-ROM | disk | FTP | other *** search
/ Revista do CD-ROM 101 / CD-ROM 101.iso / compl / maya5ple / Install_MayaPLE5_English.exe / Maya / Data1.cab / importImageFile.mel < prev    next >
Encoding:
Text File  |  2003-07-17  |  5.0 KB  |  139 lines

  1. // Copyright (C) 1997-2002 Alias|Wavefront,
  2. // a division of Silicon Graphics Limited.
  3. //
  4. // The information in this file is provided for the exclusive use of the
  5. // licensees of Alias|Wavefront.  Such users have the right to use, modify,
  6. // and incorporate this code into other products for purposes authorized
  7. // by the Alias|Wavefront license agreement, without fee.
  8. //
  9. // ALIAS|WAVEFRONT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  10. // INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
  11. // EVENT SHALL ALIAS|WAVEFRONT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  12. // CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  13. // DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  14. // TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  15. // PERFORMANCE OF THIS SOFTWARE.
  16. //
  17. // Copyright (C) 2000 Alias|Wavefront,
  18. // a division of Silicon Graphics Limited.
  19. //
  20. // The information in this file is provided for the exclusive use of the
  21. // licensees of Alias|Wavefront.  Such users have the right to use, modify,
  22. // and incorporate this code into other products for purposes authorized
  23. // by the Alias|Wavefront license agreement, without fee.
  24. //
  25. // ALIAS|WAVEFRONT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  26. // INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
  27. // EVENT SHALL ALIAS|WAVEFRONT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  28. // CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  29. // DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  30. // TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  31. // PERFORMANCE OF THIS SOFTWARE.
  32. //
  33. //
  34. //  Alias|Wavefront Script File
  35. //  MODIFY THIS AT YOUR OWN RISK
  36. //
  37. //  Creation Date:  December 8/2000
  38. //  Author:         jdc rendering
  39. //
  40. // Description:
  41. //
  42. //        This file contains a global procedure which can be called to import an
  43. //        image file as a file texture. Callers have some options when asking for
  44. //        the image file to be imported, such as whether the file texture node
  45. //        which gets created should have a placement node attached, or whether
  46. //        the image file should be used as a projection texture.
  47. //                                                
  48.  
  49. global proc string importImageFile(
  50.     string $fileName,
  51.     int $asProjection,
  52.     int $asStencil,
  53.     int $withPlacement)
  54. {
  55.     //
  56.     // Description:
  57.     //    This procedure is called when some piece of UI wants to import an
  58.     //    image file to be used as a file texture.
  59.     //    This procedure creates a file texture node and potentially other nodes
  60.     //    according to the options the caller specifies, and sets the
  61.     //    fileTextureName attribute of the created file texture node to the name
  62.     //    of the file which was imported.
  63.     //
  64.  
  65.     string $fileTextureNode;
  66.  
  67.     $fileTextureNode = renderCreateNode(
  68.         "-as2DTexture",
  69.         "",
  70.         "file",
  71.         "",
  72.         $asProjection, // projection
  73.         $asStencil, // stencil
  74.         $withPlacement, // placement
  75.         0, // shadingGroup
  76.         0, // createAndDrop
  77.         "" // editor, for createAndDrop
  78.         );
  79.  
  80.     if (`nodeType $fileTextureNode` != "file")
  81.     {
  82.         // The result node was not a file texture, which means it was either a
  83.         // projection or stencil node. We will look upstream to find the file
  84.         // texture.
  85.         //
  86.         // ASSUMPTION:
  87.         // We assume that the result node was either a projection or a stencil,
  88.         // but we do not check. We also assume that the file texture we are
  89.         // looking for is just upstream of the image attribute of the
  90.         // projection or stencil node.
  91.         //
  92.         string $sources[] = 
  93.             `listConnections
  94.                 -source true
  95.                 -destination false
  96.                 -type "file"
  97.                 ($fileTextureNode + ".image")`;
  98.         $fileTextureNode = $sources[0];
  99.     }
  100.  
  101.     string $tokenArray[];
  102.  
  103.     tokenize($fileName, "/", $tokenArray);
  104.  
  105.     string $pathTail = $tokenArray[size($tokenArray) - 1];
  106.     tokenize($pathTail, ".", $tokenArray);
  107.     string $fileNameRoot = $tokenArray[0];
  108.  
  109.     if (`match "^[0-9]+" $fileNameRoot`)
  110.     {
  111.         // The file name begins in a number, which is invalid for the name of a
  112.         // node in Maya, so we will prefix the name of the file texture node
  113.         // with "file_". 
  114.         //
  115.         // The rest of the file texture node name will be the name of the
  116.         // file, suffixed with "_1". The effect of this naming is that if the 
  117.         // user loads the same image multiple times, the resulting file 
  118.         // texture nodes will be named with suffixes _1, _2, _3, etc.
  119.         //
  120.         $fileTextureNode = 
  121.             `rename $fileTextureNode ("file_" + $fileNameRoot + "_1")`;
  122.     }
  123.     else
  124.     {
  125.         // The file texture node name will be the name of the
  126.         // file, suffixed with "_1". The effect of this naming is that if the 
  127.         // user loads the same image multiple times, the resulting file 
  128.         // texture nodes will be named with suffixes _1, _2, _3, etc.
  129.         //
  130.         $fileTextureNode = `rename $fileTextureNode ($fileNameRoot + "_1")`;
  131.     }
  132.  
  133.     setAttr ($fileTextureNode + ".fileTextureName") -type "string" $fileName;
  134.  
  135.     print("// Imported: " + $fileName + "\n");
  136.  
  137.     return $fileTextureNode;
  138. }
  139.